package com.baobao.excel.easypoi.handler;

import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl;
import com.baobao.excel.easypoi.bean.User;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Hyperlink;

/**
 * @author baobao
 * @create 2021-02-03 13:39
 * @description
 */
public class HyperlinkHandler extends ExcelDataHandlerDefaultImpl<User> {
    /**
     * 处理标有isHyperlink = true的字段
     * @param creationHelper 超链接创建帮助对象
     * @param user 实体类
     * @param name 超链接属性名称
     * @param value 超链接属性的值
     * @return
     */
    @Override
    public Hyperlink getHyperlink(CreationHelper creationHelper, User user, String name, Object value) {
        System.out.println("处理超链接");
        // 创建超链接
        Hyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.URL);
        // 设置超链接地址
        hyperlink.setAddress(user.getUrl());
        return hyperlink;
    }
}
